package com.ruoyi.wisdom.task;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.utils.tool.TimerUtils;
import com.ruoyi.wisdom.constants.IotConstants;
import com.ruoyi.wisdom.domain.IotPickGroup;
import com.ruoyi.wisdom.domain.IotPickScene;
import com.ruoyi.wisdom.domain.activity.DetectSource;
import com.ruoyi.wisdom.domain.other.OtherOptions;
import com.ruoyi.wisdom.helper.CameraPick;
import com.ruoyi.wisdom.service.IIotPickGroupService;
import com.ruoyi.wisdom.service.IIotPickSceneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class TestTask extends IotTask {

    @Autowired
    private IIotPickGroupService iotPickGroupService;

    @Autowired
    private IIotPickSceneService iotPickSceneServic;

    @Autowired
    private CameraPick cameraPick;

    //@Scheduled(fixedRate = 1000) // 每10秒执行一次
    public void testTask() {
        try {
            //test();
            test2();
        } catch (Exception e) {
            e.printStackTrace();
            printErrorLog("拉取场景数据-- redis 队列-异常：" + e.getMessage());
        }
    }

    public void test() {
        try {

            // SwapPickScene swapPickScene = JSON.parseObject(objJson, SwapPickScene.class);
            long id = 1;
            IotPickScene result = iotPickSceneServic.selectIotPickSceneById(id);
            /*
            //OtherTimes comeTime = getModelMapper().map(result, OtherTimes.class);
            ObjectMapper objectMapper = new ObjectMapper();
            List<OtherTime> comeTime = objectMapper.readValue(result.getComeTime(), objectMapper.getTypeFactory().constructCollectionType(List.class, OtherTime.class));
            System.out.println(comeTime);*/

            OtherOptions options = JSON.parseObject(result.getOptions(), OtherOptions.class);
            System.out.println(options);
            /*
            String pickGroup = options.getPickGroup().replace("]", ",").replace("[", "");
            String[] groupIds = pickGroup.split(",");
            for (String groupId : groupIds) {
                System.out.println("分组ID："+groupId);
            }*/

            String[] groupIds = {"1", "9"}; // 直接初始化数组并指定元素


            IotPickGroup groupParams = new IotPickGroup();
            groupParams.setIds(groupIds);
            List<IotPickGroup> list = iotPickGroupService.selectIotPickGroupList(groupParams);
            System.out.println(list);

            /*
            // 获取当前时间的 Calendar 实例
            Calendar calendar = Calendar.getInstance();
            // 获取当前是星期几，返回值是 1（星期日）到 7（星期六）的整数
            int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
            String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
            // 根据索引获取对应的星期几名称
            String dayOfWeekName = weekDays[dayOfWeek - 1];
            System.out.println("今天是：" + dayOfWeekName+"下标："+dayOfWeek);*/

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void test2() {
        DetectSource detectData = DetectSource.builder()
                .deviceNo("5L90R120199")
                //.file(file)
                .faceTime("2025-02-12 15:20:00")
                .build();
        detectData.setUuid(Long.parseLong("9094"));
        detectData.setWeek("3");
        detectData.setPersonType(IotConstants.USER_TYPE_STUDENT);
        cameraPick.handleStudent(detectData);
    }
}
